package com.fengshang.wedding.mvc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.fengshang.wedding.domain.model.api.User;
import com.fengshang.wedding.domain.service.api.IUserManager;

@Controller
@RequestMapping("/handleUser.do")
public class UserServiceController {

	@Autowired
	private IUserManager userManager;

	@RequestMapping(method = RequestMethod.POST)
	public ModelAndView createUser(User user) {
		System.out.println("call createUser method =" + user.getName());
		System.out.println("call userManager=" + userManager);
		User ue=new User();
		ue.setName("gembin");
		ue.setPassword("1234");
		ue.setEmail("gembin@gmail.com");
		userManager.saveUser(ue);
		return new ModelAndView("createUser");
	}

	@ModelAttribute("hello")
	public String getHello() {
		return "hello_gggg";
	}
	
	
	@RequestMapping(params = "method=login")
	public ModelAndView login(@RequestParam("id") long userId) {
		System.out.println("test:"+userId);
		return new ModelAndView("OK");
	}

}
